#include<bits/stdc++.h>
using namespace std;
mt19937 Rnd(time(0));
typedef struct{
	int key;
	int ls,rs;
	int siz;
	long long x,mn,mx,mns,mxs,addn,addx,sum;//mn:per,mx:suf
}Tree;
Tree t[400011];
int root,idx;
set<long long> st;
int New(long long x)
{
	return t[++idx] = {(int)Rnd(),0,0,1,x,0,0,0,0,0,0,x},idx;
}
void addn(int p,long long w)
{
	t[p].mn += w,t[p].mns += w * t[p].siz,t[p].addn += w;
}
void addx(int p,long long w)
{
	t[p].mx += w,t[p].mxs += w * t[p].siz,t[p].addx += w;
}
void push_down(int p)
{
	if(t[p].ls)
		addn(t[p].ls,t[p].addn),addx(t[p].ls,t[p].addx);
	if(t[p].rs)
		addn(t[p].rs,t[p].addn),addx(t[p].rs,t[p].addx);
	t[p].addn = t[p].addx = 0;
}
void push_up(int p)
{
	t[p].sum = t[t[p].ls].sum + t[p].x + t[t[p].rs].sum,t[p].mns = t[t[p].ls].mns + t[t[p].rs].mns + t[p].mn,t[p].mxs = t[t[p].ls].mxs + t[t[p].rs].mxs + t[p].mx,t[p].siz = t[t[p].ls].siz + 1 + t[t[p].rs].siz;
}
int merge(int x,int y)
{
	if(!x || !y) return x|y;
	if(t[x].key < t[y].key)
		return push_down(x),t[x].rs = merge(t[x].rs,y),push_up(x),x;
	return push_down(y),t[y].ls = merge(x,t[y].ls),push_up(y),y;
}
void splitv(int p,long long k,int& l,int& r)//split as value
{
	if(!p) return l = r = 0,void();
	push_down(p);
	if(t[p].x < k)
		return l = p,splitv(t[p].rs,k,t[p].rs,r),push_up(p);
	return r = p,splitv(t[p].ls,k,l,t[p].ls),push_up(p);
}
void splitr(int p,long long k,int& l,int& r)//split as rank
{
	if(!p) return l = r = 0,void();
	push_down(p);
	if(t[t[p].ls].siz + 1 <= k)
		return l = p,splitr(t[p].rs,k - t[t[p].ls].siz - 1,t[p].rs,r),push_up(p);
	return r = p,splitr(t[p].ls,k,l,t[p].ls),push_up(p);
}
int qrymn(int p)
{
	push_down(p);
	return t[p].ls ? qrymn(t[p].ls) : p;
}
int qrymx(int p)
{
	push_down(p);
	return t[p].rs ? qrymx(t[p].rs) : p;
}
int qryk(int p,int k)
{
	if(t[t[p].ls].siz + 1 < k)
		return push_down(p),qryk(t[p].rs,k - t[t[p].ls].siz - 1);
	else if(k <= t[t[p].ls].siz)
		return push_down(p),qryk(t[p].ls,k);
	else
		return p;
}
bool Checkin(int k)
{
	long long mn,mx;
	mn = t[qryk(root,k + 1)].mn;
	mx = t[qryk(root,st.size() - k + 1)].mx;
	return mn <= mx;
}
int L,R;//L,R: L:the first one mn[L+1] <= mx[L],R:the last one mn[R] <= mx[R - 1]
void Maintain()
{
	int mid = ((1 + st.size()) >> 1) - 1;
	L = min(max(1,L - 1),mid + 1);
	while(L <= mid && !Checkin(L))
		L++;
	while(L > 1 && Checkin(L - 1))
		L--;
	R = min(max(mid,R + 1),(int)st.size());
	while(R > mid && !Checkin(R - 1))
		R--;
	while(R < st.size() && Checkin(R))
		R++;
}
int n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	cin >> n;
	while(n--)
	{
		long long x;
		cin >> x;
		if(st.find(x) != st.end())
		{
			st.erase(x);
			int l,r,wst;
			splitv(root,x,l,r);
			splitr(r,1,wst,r);
			if(l)
				addx(l,-x);
			if(r)
				addn(r,-x);
			root = merge(l,r);
		}else{
			st.insert(x);
			int l,r;
			splitv(root,x,l,r);
			if(l)
				addx(l,x);
			if(r)
				addn(r,x);
			int p = New(x);
			t[p].mns = t[p].mn = t[l].sum + x,t[p].mxs = t[p].mx = t[r].sum + x;
			root = merge(merge(l,p),r);
		}
		if(st.size() <= 1)
		{
			cout << 0 << "\n";
			continue;
		}
		Maintain();
		if(L <= R)
		{
			int l,r,mid;
			long long res = t[root].mxs - t[root].mns;
			splitr(root,R,l,r);
			splitr(l,L - 1,l,mid);
			res -= t[qrymn(mid)].mn - t[mid].mns;
			root = merge(merge(l,mid),r);
			splitr(root,st.size() - L + 1,l,r);
			splitr(l,st.size() - R,l,mid);
			res += t[qrymn(mid)].mx - t[mid].mxs;
			root = merge(merge(l,mid),r);
			cout << res << "\n";
		}else{
			cout << t[root].mxs - t[root].mns << "\n";
		}
	}
	return 0;
}
